package configuration;

import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

/**
 * Created by wzl on 19-12-9.
 */
public class KafkaServerConfig {
    private String bootstrap_servers;
    private String topic1;
    private String topic2;
    private String measurement;
    private long  sleep_ms=-1;

    public void setBootstrap_servers(String bootstrap_servers) {
        this.bootstrap_servers = bootstrap_servers;
    }

    public String getBootstrap_servers() {
        return bootstrap_servers;
    }

    public void setTopic1(String topic1) {
        this.topic1 = topic1;
    }

    public String getTopic1() {
        return topic1;
    }

    public String getTopic2() {
        return topic2;
    }

    public void setTopic2(String topic2) {
        this.topic2 = topic2;
    }

    public String getMeasurement() {
        return measurement;
    }

    public void setMeasurement(String measurement) {
        this.measurement = measurement;
    }

    public long getSleep_ms() {
        return sleep_ms;
    }

    public void setSleep_ms(long sleep_ms) {
        this.sleep_ms = sleep_ms;
    }

    public static KafkaServerConfig initFromFile(String filepath) throws FileNotFoundException {
        Yaml yaml = new Yaml();
        KafkaServerConfig config = yaml.loadAs(new FileInputStream(new File(filepath)),
                KafkaServerConfig.class);
        return config;
    }

    @Override
    public String toString() {
        return "KafkaServerConfig {" +
                "\nbootstrap_servers = " + bootstrap_servers +
                "\ntopic1 = " + topic1 +
                "\ntopic2 = " + topic2 +
                "\nmeasurement = " + measurement +
                "\nsleep_ms = " + sleep_ms +
                "\n}";
    }
}
